package com.ibiaoke.system.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.exception.DaoException;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.system.constant.ShopConstant;
import com.ibiaoke.system.entity.Shop;
import com.ibiaoke.system.entity.ShopExample;
import com.ibiaoke.system.mapper.ShopMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by SuXin on 2017/6/20.
 */
@Repository
public class ShopDao extends BaseDao<Shop,ShopExample,Integer,ShopMapper> {

    @Autowired
    private ShopMapper shopMapper;


    @Override
    public ShopMapper getMapper() {
        return shopMapper;
    }

    public Shop getShopByShopId(Integer shopId) {
        ShopExample example =new ShopExample();
        ShopExample.Criteria criteria = example.createCriteria();
        criteria.andDelFlagEqualTo((byte) CommonConsts.NO);
        criteria.andShopIdEqualTo(shopId);
        return getByExample(example);
    }

    public List<Shop> listShop() {
        ShopExample shopExample =new ShopExample();
        ShopExample.Criteria  criteria = shopExample.createCriteria();
        criteria.andDelFlagEqualTo((byte)CommonConsts.NO);
        return shopMapper.selectByExample(shopExample);
    }

    public int relevanceShop(Shop shop) {
        ShopExample example = new ShopExample();
        example.createCriteria().andShopIdEqualTo(shop.getShopId());
        Shop shop1 = new Shop();
        shop1.setUserId(shop.getUserId());
        return shopMapper.updateByExampleSelective(shop1, example);
    }
}
